package com.design.pattern.structure.conposite.demo.transparent;

import java.util.ArrayList;
import java.util.List;

public class CoursePage extends CourseComponent{
    private List<CourseComponent> items = new ArrayList<>();
    private String name;
    private Integer level;
    private Double price;

    public CoursePage(String name, Integer level) {
        this.name = name;
        this.level = level;
        this.price = 0.0;
    }

    @Override
    public void addChild(CourseComponent component) {
        this.items.add(component);
        this.price += component.getPrice();
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public double getPrice() {
        return this.price;
    }

    @Override
    public void print() {
        System.out.println(this.name);
        for(CourseComponent c : items) {
            if(this.level != null) {
                for(int i = 0; i < this.level; i++) {
                    System.out.print("  ");
                }
                for(int i = 0; i < this.level; i++) {
                    if(i == 0) {
                        System.out.print("+");
                    }
                    System.out.print("-");
                }
            }
            c.print();
        }
    }
}
